import axiosInstance from "./index"

//4


const axios = axiosInstance

//GET
export const getBlogs = (url) => {
  const tk = localStorage.getItem('token')
  return axios.get(url, {
    headers: {
      'X-Access-Token': tk,
    },
  })
}

//注册
export const postUser = (name, psw) =>{
  return axios.post("/api/users/signup", {
    'username': name,
    'password': psw,
  })
}

//更改用户的用户名和密码
export const postUserChange = (url, name, psw) =>{
  const tk = localStorage.getItem('token')
  return axios.patch(url, {
    'username': name,
    'password': psw,
  }, {
    headers: {
      'X-Access-Token': tk,
    },
  })
}
//登录
export const postLogin = (name, psw) =>{
  return axios.post("/api/users/signin/", {
    'username': name,
    'password': psw,
  })
}

//订阅
export const postSubscribe = (fans, blogger) =>{
  const tk = localStorage.getItem('token')
  return axios.post("/api/subscribe/", {
    'fans': fans,
    'blogger': blogger,
  }, {
    headers: {
      'X-Access-Token': tk,
    },
  })
}


//上传图片
export const postImg = (data) => {
  const tk = localStorage.getItem('token')
  return axios.post("/api/avatar/",
    data, {
      headers: {
        'X-Access-Token': tk,
      },
    })
}



//上传博客
export const postBlog = (username, title, image, content, token) => {
  const tk = localStorage.getItem('token')
  return axios.post("/api/article/", {
    'a_author': username,
    'a_title': title,
    'a_avatar': image,
    'a_content': content,
  },{
    headers: {
      'X-Access-Token': tk,
    },
  })
}
//上传评论
export const postComment = (content, article, username, reply) =>{
  const tk = localStorage.getItem('token')
  return axios.post("/api/comment/", {
    'c_content': content,
    'article': article,
    'c_author': username,
  },{
    headers: {
      'X-Access-Token': tk,
    },
  })
}

//上传提交
export const postSubmit = (id, file_name, time_limit, memory_limit, cases, code) =>{
  const tk = localStorage.getItem('token')
  return axios.post("/api/submit", {
    id, file_name, time_limit, memory_limit, cases, code, state: 0
  }, {
    headers: {
      'X-Access-Token': tk,
    },
  })
}
//上传测试用例
export const postCase = (data) => {
  const tk = localStorage.getItem('mg-token')
  return axios.post("/api/case/",
    data, {
      headers: {
        'Y-Access-Token': tk,
      },
    })
}
//管理员登录
export const postManagerLogin = (name, psw) =>{
  return axios.post("/api/administrator/signin/", {
    'username': name,
    'password': psw,
  })
}

//上传问题
export const postQuestion = (username,
                             title,
                             avatar,
                             content,
                             time_limit,
                             memory_limit,
                             cases,) => {
  const tk = localStorage.getItem('mg-token')
  return axios.post("/api/question/", {
    username,
    title,
    avatar,
    content,
    time_limit,
    memory_limit,
    cases,
  },{
    headers: {
      'Y-Access-Token': tk,
    },
  })
}

//10
